package utils.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

public final class JsonResponse{
    private int code;
    private String msg;
    private Object data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    public void setMsg(ResponseStatus status) {
        this.msg = status.getMsg();
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    public void setCode(ResponseStatus status) {
        this.code = status.getCode();
    }

    public JsonResponse(int code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public JsonResponse(int code, String msg){
        this.code = code;
        this.msg = msg;
    }
    public JsonResponse(ResponseStatus status){
        this.msg = status.getMsg();
        this.code = status.getCode();
    }

    /**
     * 默认使用成功状态
     */
    public JsonResponse(){
        this.msg = ResponseStatus.SUCCESS.getMsg();
        this.code = ResponseStatus.SUCCESS.getCode();
    }

    public void set(ResponseStatus status, String msg){
        this.code = status.getCode();
        this.msg = msg;
    }

    public String toString(){
        return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect,
                SerializerFeature.WriteDateUseDateFormat);
    }
}